//
//  UserViewModel.m
//  didacar
//
//  Created by 度周末网络-王腾 on 15/12/8.
//  Copyright © 2015年 dzmmac. All rights reserved.
//

#import "UserViewModel.h"
#import "SmsCodeModel.h"
#import "UserInfoModel.h"
#import "UserInfoManager.h"
@implementation UserViewModel

/**
 *  发送验证码
 *
 *  @param resultBlock
 */
-(void)sendSmsCode:(DealDataResultBlock)resultBlock{
    
    NSMutableDictionary *postData = [[NSMutableDictionary alloc ] init];
    [postData setObj:self.mobile forKey:@"Mobile"];
    
    WEAKSELF
    [[BaseHttpRequest sharedInstance] sendRequestToPost:SendSmsCode withData:postData alertMessage:@"" success:^(NSDictionary *dicData) {
        weakSelf.smsCodeModel = [[SmsCodeModel alloc ] initWithDictionary:dicData];
        resultBlock(1,weakSelf.smsCodeModel,weakSelf.smsCodeModel.Message);
    } error:^(NSString *errorMsg) {
        
        resultBlock(0,nil,errorMsg);
    }];
}

-(void)login:(DealDataResultBlock)resultBlock{
    
    NSMutableDictionary *postData = [[NSMutableDictionary alloc ] init];
    [postData setObj:self.mobile  forKey:@"Mobile"];
    [postData setObj:self.smsCode forKey:@"SmsCode"];
  
    [[BaseHttpRequest sharedInstance] sendRequestToPost:LOGIN withData:postData alertMessage:@"" success:^(NSDictionary *dicData) {
        
        UserInfoModel *userInfo = [[UserInfoModel alloc ] initWithDictionary:dicData];
        [USERINFOManager saveUserInfo:userInfo];
        [USERINFOManager updateLoginStatus:YES];
        
        resultBlock(1,nil,nil);
    } error:^(NSString *errorMsg) {
        
        resultBlock(0,nil,errorMsg);
    }];
}

@end
